<template>
  <div class="app-container">
    <h1>任务详情</h1>
    <table class="detail-table" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>任务名称</td><td>{{taskData.taskName}}</td>
         <td>店铺名称</td><td>{{taskData.storeName}}</td>
      </tr>
      
       <tr>
        <td>产品名称</td><td>{{taskData.productName}}</td>
         <td>关键词</td><td>{{taskData.keywords}}</td>
      </tr>
       <tr>
        <td>链接</td><td>{{taskData.url}}</td>
        <td>主图</td><td>{{taskData.picture}}</td>
      </tr>
       <tr>
        <td>金额</td><td>{{taskData.price}}</td>
        <td>日期</td><td>{{taskData.tastDate}}</td>
      </tr>
      <tr>
        <td>当天成交量</td><td>{{taskData.dailyTradingVolume}}</td>
        <td>预留成交量</td><td>{{taskData.reservedTradingVolume}}</td>
      </tr>
       <tr>
        <td>剩余成交量</td><td>{{taskData.remainVolume}}</td>
         <td>评价信息</td><td>{{taskData.evaluation}}</td>
      </tr>
       <tr>
        <td>状态</td><td>{{taskData.status}}</td>
        <td>备注</td><td>{{taskData.remark}}</td>
      </tr>
     
    </table>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="任务明细ID" align="center" prop="taskDetailId" />
      <el-table-column label="任务ID" align="center" prop="taskId" />
      <el-table-column label="交易量" align="center" prop="tradingVolume" />
      <el-table-column label="买家旺旺" align="center" prop="buyerNick" />
      <el-table-column label="交易类型" align="center" prop="tradingType" :formatter="tradingTypeFormat" />
      <el-table-column label="订单类型" align="center" prop="orderType" :formatter="orderTypeFormat" />
      <el-table-column label="返款类型" align="center" prop="rebatesType" :formatter="rebatesTypeFormat" />
      <el-table-column label="用户类型" align="center" prop="buyerType" :formatter="buyerTypeFormat" />
      <el-table-column label="返款渠道" align="center" prop="rebatesChannel" :formatter="rebatesChannelFormat" />
      <el-table-column label="返款渠道明细" align="center" prop="rebatesWay" />
      <el-table-column label="返款金额" align="center" prop="rebatesAmount" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="责任人 ID" align="center" prop="responsibleUserId" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { detailIdList, getDetail, delDetail, addDetail, updateDetail, exportDetail } from "@/api/system/detail";

export default {
  name: "Detail",
  components: {
  },
  data() {
    return {
      taskData:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务完成明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 交易类型字典
      tradingTypeOptions: [],
      // 订单类型字典
      orderTypeOptions: [],
      // 返款类型字典
      rebatesTypeOptions: [],
      // 用户类型字典
      buyerTypeOptions: [],
      // 返款渠道字典
      rebatesChannelOptions: [],
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId: null,
        tradingVolume: null,
        buyerNick: null,
        tradingType: null,
        orderType: null,
        rebatesType: null,
        buyerType: null,
        rebatesChannel: null,
        rebatesWay: null,
        rebatesAmount: null,
        status: null,
        responsibleUserId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taskId: [
          { required: true, message: "任务ID不能为空", trigger: "blur" }
        ],
        buyerNick: [
          { required: true, message: "买家旺旺不能为空", trigger: "blur" }
        ],
        orderType: [
          { required: true, message: "订单类型不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    // console.log(this.$route.params.id)
    // if(this.$route.params.row){
    //    this.taskData = this.$route.params.row
    // }
    this.getList();
    this.getDicts("trading_type").then(response => {
      this.tradingTypeOptions = response.data;
    });
    this.getDicts("order_type").then(response => {
      this.orderTypeOptions = response.data;
    });
    this.getDicts("rebates_type").then(response => {
      this.rebatesTypeOptions = response.data;
    });
    this.getDicts("user_type").then(response => {
      this.buyerTypeOptions = response.data;
    });
    this.getDicts("channel_type").then(response => {
      this.rebatesChannelOptions = response.data;
    });
    this.getDicts("risk_detail_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询任务完成明细列表 */
    getList() {
      this.loading = true;
      detailIdList(this.$route.params.id).then(response => {
        // console.log(response)
        this.taskData=response.data;
        this.detailList = response.data.taskDetails;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 交易类型字典翻译
    tradingTypeFormat(row, column) {
      return this.selectDictLabel(this.tradingTypeOptions, row.tradingType);
    },
    // 订单类型字典翻译
    orderTypeFormat(row, column) {
      return this.selectDictLabel(this.orderTypeOptions, row.orderType);
    },
    // 返款类型字典翻译
    rebatesTypeFormat(row, column) {
      return this.selectDictLabel(this.rebatesTypeOptions, row.rebatesType);
    },
    // 用户类型字典翻译
    buyerTypeFormat(row, column) {
      return this.selectDictLabel(this.buyerTypeOptions, row.buyerType);
    },
    // 返款渠道字典翻译
    rebatesChannelFormat(row, column) {
      return this.selectDictLabel(this.rebatesChannelOptions, row.rebatesChannel);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        taskDetailId: null,
        taskId: null,
        tradingVolume: null,
        buyerNick: null,
        tradingType: null,
        orderType: null,
        rebatesType: null,
        buyerType: null,
        rebatesChannel: null,
        rebatesWay: null,
        rebatesAmount: null,
        status: "0",
        responsibleUserId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.taskDetailId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务完成明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const taskDetailId = row.taskDetailId || this.ids
      getDetail(taskDetailId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改任务完成明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.taskDetailId != null) {
            updateDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const taskDetailIds = row.taskDetailId || this.ids;
      this.$confirm('是否确认删除任务完成明细编号为"' + taskDetailIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(taskDetailIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有任务完成明细数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDetail(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>

<style lang="scss">
.detail-table{
  width: 100%;
  td{
    line-height: 25px;
    font-size: 14px;
    text-align: left;
    border-top: 1px solid #ccc;
    padding: 0 10px;
    color: #444;
    &:nth-child(odd){
      background: #e9e9e9;
      width:100px;
      text-align: right;
      font-weight: bold;
    }
  }
}
</style>